package com.origin.src.datasource;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;

@Component
public class DataSourceBean {

    @Bean("HikariDB")
    @ConditionalOnMissingBean(DataSource.class)
    public static DataSource dataSource() {
        HikariConfig hikariConfig = new HikariConfig();
        hikariConfig.setJdbcUrl("jdbc:mysql://localhost:3306/app?serverTimezone=GMT%2B8&autoReconnect=true&failOverReadOnly=false&autoReconnect=true&autoReconnectForPools=true");
        hikariConfig.setUsername("root");
        hikariConfig.setPassword("root");
        hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
        hikariConfig.setMaximumPoolSize(8);
        hikariConfig.setMinimumIdle(0);
        hikariConfig.setPoolName("DataSource-Hikari");
        return new HikariDataSource(hikariConfig);
    }

//
//    @Bean
//    public static DataSourceTransactionManager dataSourceTransactionManager(DataSource dataSource) {
//        DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
//    }
}
